<?php
/**
 * Created by PhpStorm.
 * User: adminstrator
 * Date: 2018/2/8
 * Time: 16:35
 */
header("Content-type:text/html;charset=utf-8");
date_default_timezone_set('PRC');
include_once("./Db_pdo.class.php");
echo '<pre>';
$DB=new Db_pdo("cxh_v3","cxhv3","cxhv3pwd!@#");
//$DB=new Db_pdo("root","root","jmshop");


//  单独补贴 每天数据记录 
// //车辆补贴
// $field = 'su.id,su.aplc_totel_retime,su.aplc_totel_money,su.aplc_totel_days,su.aplc_totel_balance,su.aplc_re_money,su.aplc_re_money_p,su.aplc_re_integral,su.aplc_re_integral_p,su.aplc_re_fee,su.aplc_re_fee_p,su.member_id,me.credit2,me.credit1,me.cxhname';
// $sql = 'select '.$field.' from ims_cxh_apply_subsidy_car as su inner join ims_ewei_shop_member as me on su.member_id=me
// 	.id where su.aplc_status=1 and su.is_all_back=1 and su.is_month_back=1 and su.member_id=2676';

// $data= $DB->new_query($sql);
// $data = $data->fetchAll(PDO::FETCH_ASSOC); 
// // print_r($data);
// $nowtime =1535385631;
// $nowtimes =date('Y-m-d',$nowtime);
// $newarrs = array();
// $newarrs1 = array();
// foreach ($data as $key => $value) {
// 			//判断已经返还完的
// 			if($value['aplc_totel_money']>$value['aplc_re_money']){
				
// 				//每天返款总金额
// 				$money = round($value['aplc_totel_balance']/($value['aplc_totel_days']-$value['aplc_totel_retime']),2);
// 				// echo $money;
// 				//剩余金额(防止返款不足的情况)
// 				if($value['aplc_totel_balance']<$money){
// 					$param['aplc_totel_balance'] = 0;
// 					$money = $value['aplc_totel_balance'];
// 				}else{
// 					$param['aplc_totel_balance'] = $value['aplc_totel_balance']-$money;
// 				}


// 				// echo $money;
// 				//金额(判断是否全返款还是其他)
// 				//判断是否有平台维护费
// 				$fee_money =0;
// 				$balance_money =$money;
// 				if($value['aplc_re_fee_p']>0){
// 					$fee_money = round($money*$value['aplc_re_fee_p'],2);
// 					$balance_money =  round($balance_money-$fee_money,2);
// 				}

// 				//判断是否有购物积分
// 				$points_money =0;
// 				if($value['aplc_re_integral_p']>0){
// 					$points_money = round($money*$value['aplc_re_integral_p'],2);
// 					$balance_money = round($balance_money-$points_money,2);
// 				}



// 				//已返款天数
// 				$param['aplc_totel_retime'] = $value['aplc_totel_retime']+1;
// 				//已返金额
// 				$param['aplc_re_money']  = $value['aplc_re_money']+$money;
// 				//已返维护费
// 				$param['aplc_re_fee'] = $value['aplc_re_fee'] +$fee_money;
// 				//已返积分
// 				$param['aplc_re_integral'] = $value['aplc_re_integral'] +$points_money;
// 				// echo $balance_money;
// 				// print_r($param);
// 				$condition['id'] = $value['id'];
// 				//处理申请表

				

// 				$DB->table("ims_cxh_apply_subsidy_car")->where("id=".$value['id'])->update($param);
// 				//添加member表的钱
// 				$params = 'credit2=credit2+'.$balance_money.', credit3=credit3-'.$money.', credit1=credit1+'.$points_money;
// 				$condition1['id'] = $value['member_id'];


// 				$sql1 = "update ims_ewei_shop_member set ".$params.' where id='.$value['member_id'];
// 				// echo $sql1;
// 				$DB->new_query($sql1);
// 				//exit;
// 				//$res[]=pdo_update('ewei_shop_member',$params,$condition1);


// 				// //back表记录
// 			    $log['apb_type'] = 1;
// 				$log['bus_id'] = $value['id'];

// 				$log['apb_money'] = $balance_money;
// 				$log['apb_fee'] = $fee_money;
// 				$log['member_id'] = $value['member_id'];
// 				$log['apb_intgral'] = $points_money;
// 				$log['ctime'] =$nowtime;
// 				// print_r($log);
// 				// exit;
// 				//$res[]=pdo_insert('cxh_apply_subsidy_back',$log);
// 				$DB->table("ims_cxh_apply_subsidy_back")->insert($log);

// 				//一个用户拥有多个车辆的情况
				
// 				$old = $value['credit2'];
// 				$old1 = $value['credit1'];
// 				if(isset($newarrs[$value['member_id']])){
// 					$old = $newarrs[$value['member_id']];
// 				}
// 				if(isset($newarrs1[$value['member_id']])){
// 					$old1 = $newarrs1[$value['member_id']];
// 				}

// 				// //一总收入
// 				$tol_log['cash_bus_type'] = 1;
// 				$tol_log['cash_type'] = 1;
// 				$tol_log['cash_old'] = $old;
// 				$tol_log['cash_now'] = $money+$old;
// 				$tol_log['cash_num'] = '+'.$money;
// 				$tol_log['remark'] = '[车辆补贴返款] 补贴总金额 '.$nowtimes;
// 				$tol_log['member_id'] = $value['member_id'];
// 				$tol_log['ctime'] =$nowtime;
				
// 				$DB->table("ims_cxh_cash_log")->insert($tol_log);
// 				if($value['aplc_re_fee_p']>0){
// 					//平台费
// 					$fee_log['cash_bus_type'] = 1;
// 					$fee_log['cash_type'] = 1;
// 					$fee_log['cash_now'] = $money+$old-$fee_money;
// 					$fee_log['cash_old'] = $money+$old;
// 					$fee_log['cash_num'] = '-'.$fee_money;
// 					$fee_log['remark'] = '[车辆补贴返款] 扣除平台维护费 ' .$nowtimes;
// 					$fee_log['member_id'] = $value['member_id'];
// 					$fee_log['ctime'] =$nowtime;
// 					//$res[]=pdo_insert('cxh_cash_log',$fee_log);
// 					$DB->table("ims_cxh_cash_log")->insert($fee_log);
// 				}
// 				if($value['aplc_re_integral_p']>0){
// 					//购物积分
// 					$fee_log['cash_bus_type'] = 1;
// 					$fee_log['cash_type'] = 1;
// 					$fee_log['cash_now'] = $money+$old-$fee_money-$points_money;
// 					$fee_log['cash_old'] = $money+$old-$fee_money;
// 					$fee_log['cash_num'] = '-'.$points_money;
// 					$fee_log['remark'] = '[车辆补贴返款] 扣除购物积分 ' .$nowtimes;
// 					$fee_log['member_id'] = $value['member_id'];
// 					$fee_log['ctime'] =$nowtime;
// 					$DB->table("ims_cxh_cash_log")->insert($fee_log);
// 					//$res[]=pdo_insert('cxh_cash_log',$fee_log);

// 					//购物积分
// 					$fee_log['cash_bus_type'] = 1;
// 					$fee_log['cash_type'] = 2;
// 					$fee_log['cash_now'] = $old1+$points_money;
// 					$fee_log['cash_old'] = $old1;
// 					$fee_log['cash_num'] = '+'.$points_money;
// 					$fee_log['remark'] = '[车辆补贴返款] 获得购物积分 ' .$nowtimes;
// 					$fee_log['member_id'] = $value['member_id'];
// 					$fee_log['ctime'] =$nowtime;
// 					$DB->table("ims_cxh_cash_log")->insert($fee_log);
// 					//$res[]=pdo_insert('cxh_cash_log',$fee_log);

// 				}



// 				$newarrs[$value['member_id']] = $balance_money+$old;
// 				$newarrs1[$value['member_id']] = $points_money+$old1;
				

				
// 			}

// 		}
// $num = 50;
// $arr =array();
// foreach ($data as $key => $value) {
// 	for($i=0;$i<$num;$i++){
// 		$param['ctime']=  1533746006-86400*$i;
// 		$param['cash_bus_type'] =1;
// 		$param['cash_type'] =1;
// 		$param['cash_now'] = 53.9;
// 		$param['cash_old'] =0;
// 		$param['cash_num'] =53.9;
// 		$param['remark'] = '[车辆补贴返款] 补贴总金额 '.date('Y-m-d',$param['ctime']);
// 		$param['member_id'] = 1121;
// 		$arr[] = $param;
// 	}

	
// }

// foreach ($arr as $key1 => $value1) {
	
// 	$DB->table("ims_cxh_cash_log")->insert($value1);
// }
// print_r($arr);







///代理商补贴
//
//

// $field = 'su.id,su.apla_totel_retime,su.apla_totel_money,su.apla_totel_days,su.apla_totel_balance,su.apla_re_money,su.apla_re_money_p,su.apla_re_integral,su.apla_re_integral_p,su.apla_re_fee,su.apla_re_fee_p,su.member_id,me.credit2,me.credit1,me.cxhname';
// 	$sql = 'select '.$field.' from ims_cxh_apply_subsidy_agent as su inner join ims_ewei_shop_member as me on su.member_id=me
// 	.id where su.apla_status=1 and su.is_all_back=1 and su.is_month_back=1';

// $data= $DB->new_query($sql);
// $data = $data->fetchAll(PDO::FETCH_ASSOC); 
// $nowtime = 1533830426;
// $nowtimes =date('Y-m-d',$nowtime);


// if($data){

// 		foreach ($data as $key => $value) {

// 			if($value['apla_totel_money']>$value['apla_re_money']){
// 				//每天返款总金额
// 				$money = round($value['apla_totel_balance']/($value['apla_totel_days']-$value['apla_totel_retime']),2);

// 				//剩余金额(防止返款不足的情况)
// 				if($value['apla_totel_balance']<$money){
// 					$param['apla_totel_balance'] = 0;
// 					$money = $value['apla_totel_balance'];
// 				}else{
// 					$param['apla_totel_balance'] = $value['apla_totel_balance']-$money;
// 				}
// 				$fee_money =0;
// 				if($value['apla_re_fee_p']>0){
// 					$fee_money = round($money*$value['apla_re_fee_p'],2);
// 					$balance_money =  round($money-$fee_money,2);
// 				}else{
// 					$balance_money = $money;
// 				}

				
// 				//已返款天数
// 				$param['apla_totel_retime'] = $value['apla_totel_retime']+1;
// 				//已返金额
// 				$param['apla_re_money']  = $value['apla_re_money']+$money;
// 				//已返积分
// 				// $param['apla_re_integral']  = $value['apla_re_integral']+$point_money;
// 				//平台运维总费
// 				$param['apla_re_fee']  = $value['apla_re_fee']+$fee_money;
// 				$condition['member_id'] = $value['member_id'];


// 				//处理申请表
// 				// $res[]=pdo_update('cxh_apply_subsidy_agent',$param,$condition);
				
// 				//添加member表的钱 
// 				$params = 'credit2=credit2+'.$balance_money;
// 				$condition1['id'] = $value['member_id'];
// 				// $res[]=pdo_update('ewei_shop_member',$params,$condition1);


// 				//back表记录
// 			    $log['apb_type'] = 2;
// 				$log['bus_id'] = $value['id'];
// 				$log['apb_money'] = $money;
// 				$log['apb_fee'] = $fee_money;
// 				$log['member_id'] = $value['member_id'];
// 				$log['apb_intgral'] = 0;
// 				$log['ctime'] =$nowtime;
// 				$DB->table("ims_cxh_apply_subsidy_back")->insert($log);
// 				// $res[]=pdo_insert('cxh_apply_subsidy_back',$log);

// 				//一总收入
// 				$tol_log['cash_bus_type'] = 2;
// 				$tol_log['cash_type'] = 1;
// 				$tol_log['cash_now'] = $money+$value['credit2'];
// 				$tol_log['cash_old'] = $value['credit2'];
// 				$tol_log['cash_num'] = '+'.$money;
// 				$tol_log['remark'] = '[代理运营补贴] 补贴总金额'.$nowtimes;
// 				$tol_log['member_id'] = $value['member_id'];
// 				$tol_log['ctime'] =$nowtime;
// 				// $res[]=pdo_insert('cxh_cash_log',$tol_log);

// 				if($value['apla_re_fee_p']>0){
// 					//平台费
// 					$fee_log['cash_bus_type'] = 2;
// 					$fee_log['cash_type'] = 1;
// 					$fee_log['cash_now'] = $balance_money+$value['credit2'];
// 					$fee_log['cash_old'] = $value['credit2'];
// 					$fee_log['cash_num'] = '-'.$fee_money;
// 					$fee_log['remark'] = '[代理运营补贴] 扣除平台维护费 ' .$nowtimes;
// 					$fee_log['member_id'] = $value['member_id'];
// 					$fee_log['ctime'] =$nowtime;
// 					// $res[]=pdo_insert('cxh_cash_log',$fee_log);
// 				}

				
// 			}
// 		}
// 	}
// print_r($data);
// exit;








//积分 的 修改bug
// $sql = '
// SELECT
	
// 	su.member_id,
// 	sum(su.aplc_totel_balance) as ac,
// 	me.credit3
// FROM
// 	ims_cxh_apply_subsidy_car AS su
// INNER JOIN ims_ewei_shop_member AS me ON me.id = su.member_id
// WHERE
// 	su.aplc_status = 1

// GROUP BY member_id 
// ORDER BY su.member_id  ASC
// ';
// $datas= $DB->new_query($sql);
// $datas = $datas->fetchAll(PDO::FETCH_ASSOC); 
// // print_r($datas);
// // exit;
// $arr =array();
// foreach ($datas as $key => $value) {
	
// 	// echo $es;

// 	// echo '<br>';
// 	// $tt = $DB->db->query($es);
// 	if($value['ac']!==$value['credit3']){
// 		$arr[] = $value;
// 	}
// }
// print_r($arr);
// foreach ($arr as $key1 => $value1) {
// 	// print_r($value1);
// 	$es = 'update ims_ewei_shop_member set credit3='.$value1['ac'] .' where id ='.$value1['member_id'];
// 	$tt = $DB->db->query($es);
// }
// print_r($datas);


//购车规则的修改

// $sql = '
// SELECT * FROM ims_cxh_apply_subsidy_car WHERE aplc_status =1 and aplc_re_integral_p >0

// ';
// $data= $DB->new_query($sql);
// $data = $data->fetchAll(PDO::FETCH_ASSOC); 
// // print_r($data);
// foreach ($data as $key => $value) {
// 	$money = round($value['aplc_re_money']*0.2,2);
// 	// $money = round($value['aplc_totel_money'] -  $value['aplc_totel_balance'] -$value['aplc_re_money'],2);
// 	echo $money*14;
// 	echo '<br>';


// 	// $es = 'update ims_cxh_apply_subsidy_car set aplc_re_integral='.$money.' where id ='.$value['id'];
// 	// $tt = $DB->db->query($es);
// 	// echo $es;
// 	// echo '<br>';
// }
// $sql = 'SELECT * FROM ims_cxh_apply_subsidy_car WHERE aplc_status =1 and aplc_re_integral_p >0';
// $data= $DB->new_query($sql);
// $data = $data->fetchAll(PDO::FETCH_ASSOC); 
// foreach ($data as $key => $value) {
// 	if($value['aplc_totel_money']>$value['aplc_re_money']){
				
// 				//每天返款总金额
// 				$money = round($value['aplc_totel_balance']/($value['aplc_totel_days']-$value['aplc_totel_retime']),2);
// 				// echo $money;
// 				//剩余金额(防止返款不足的情况)
// 				if($value['aplc_totel_balance']<$money){
// 					$param['aplc_totel_balance'] = 0;
// 					$money = $value['aplc_totel_balance'];
// 				}else{
// 					$param['aplc_totel_balance'] = $value['aplc_totel_balance']-$money;
// 				}


// 				// echo $money;
// 				//金额(判断是否全返款还是其他)
// 				//判断是否有平台维护费
// 				$fee_money =0;
// 				$balance_money =$money;
// 				if($value['aplc_re_fee_p']>0){
// 					$fee_money = round($money*$value['aplc_re_fee_p'],2);
// 					$balance_money =  round($balance_money-$fee_money,2);
// 				}

// 				//判断是否有购物积分
// 				$points_money =0;
// 				if($value['aplc_re_integral_p']>0){
// 					$points_money = round($money*$value['aplc_re_integral_p'],2);
// 					$balance_money = round($balance_money-$points_money,2);
// 				}



// 				//已返款天数
// 				$param['aplc_totel_retime'] = $value['aplc_totel_retime']+1;
// 				//已返金额
// 				$param['aplc_re_money']  = $value['aplc_re_money']+$money;
// 				//已返维护费
// 				$param['aplc_re_fee'] = $value['aplc_re_fee'] +$fee_money;
// 				//已返积分
// 				$param['aplc_re_integral'] = $value['aplc_re_integral'] +$points_money;
// 				// echo $balance_money;
// 				// print_r($param);
// 				$condition['id'] = $value['id'];
// 				//处理申请表
// 				// $res[]=pdo_update('cxh_apply_subsidy_car',$param,$condition);
// 				$sum_point = $points_money*14;
				
// 				// echo '<br>';
// 				// echo $value['aplc_re_integral'];
				

// 				if($sum_point>$value['aplc_re_integral']){
// 					$aplc_re_integral = $value['aplc_re_integral'];
// 				}else{
// 					$aplc_re_integral = $sum_point;
// 				}

// 				// echo '<br>';
// 				// echo $aplc_re_integral;
// 				// echo '<br>';
// 				//添加member表的钱
// 				$params = 'credit1=credit1+'.$aplc_re_integral;
// 				$condition1['id'] = $value['member_id'];
// 				$sqls = 'update ims_ewei_shop_member set '.$params.' where id ='.$value['member_id'];
// 				// echo $sqls;
// 				// $tt = $DB->db->query($sqls);

				




				
// 			}
// }
// print_r($data);

// $sql = "SELECT * FROM ims_cxh_cash_log WHERE cash_bus_type =1 and remark like '%扣除平台维护费%' ";
// $data= $DB->new_query($sql);
// $data = $data->fetchAll(PDO::FETCH_ASSOC); 
// // print_r($data);
// // exit;
// foreach ($data as $key => $value) {
// 	$result = preg_replace('/([\x80-\xff]*)/i','',$value['remark']);
// 	// print_r($result);
// 	$time = substr($result,2);
// 	$remark =$time;
// 	// $time = explode('',$result);
// 	// print_r($param);
// 	// echo '<br>';
// 	if($value['cash_num']>0){
// 		$sqls = "update ims_cxh_cash_log set remark = '[车辆补贴返款] 扣除购物积分".$remark."',cash_num=-".$value['cash_num']." where id =".$value['id'];
// 	}else{
// 		$sqls = "update ims_cxh_cash_log set remark = '[车辆补贴返款] 扣除购物积分".$remark."' where id =".$value['id'];
// 	}
	
// 	// echo $sqls;
// 	// echo '<br>';
// 	$DB->db->query($sqls);
// }
// print_r($data);


// $sql1 = 'select * from ims_cxh_apply_subsidy_back where apb_type =1 and apb_fee >0';

// $data= $DB->new_query($sql1);
//  $data = $data->fetchAll(PDO::FETCH_ASSOC); 
//  // print_r($data);
//  // exit;
//  foreach ($data as $key => $value) {
//  	$sqls = "update ims_cxh_apply_subsidy_back set apb_intgral = ".$value['apb_fee'].",apb_fee = 0 where id =".$value['id'];
//  	// echo $sqls;
//  	// $DB->db->query($sqls);
//  	// echo $sqls;
//  	// echo '<br>';
//  }
 // print_r($data);





//这是 差值比较的地方
// $values ='';
// $data = unserialize(file_get_contents('oldcar.txt')); 
// foreach ($data as $key => $value) {

// 	  $values.=$value['user_id'].',';
// }
// $values = rtrim($values, ",");
// // print_r($values);

// $sql = "SELECT
// 	a.member_id,
// 	(a.apb_money + a.apb_intgral+a.apb_fee) AS money,
// 	b.cxhname,
// 	FROM_UNIXTIME(ctime,'%Y-%m-%d') as time2
// FROM
// 	ims_cxh_apply_subsidy_back AS a
// LEFT JOIN ims_ewei_shop_member AS b ON a.member_id = b.id
// WHERE
// 	a.apb_type = 2
// AND a.ctime BETWEEN 1535299259
// AND 1535385599
// AND a.member_id IN (".$values.")
// ORDER BY
// 	a.member_id ASC
// "; 

// echo $sql;
// exit;
// // echo md5(654321);
// // exit;
// $data1= $DB->new_query($sql);
// $data1 = $data1->fetchAll(PDO::FETCH_ASSOC); 
// print_r($data1);




//代理商返款退回


// $sql = "SELECT
// 	*
// FROM
// 	ims_cxh_apply_subsidy_back
// WHERE
// 	apb_type = 2
// AND ctime BETWEEN 1535299200
// AND 1535385540
// ORDER BY member_id ASC";
// $data1= $DB->new_query($sql);
// $data1 = $data1->fetchAll(PDO::FETCH_ASSOC); 
// // print_r($data1);
// // exit;
// foreach ($data1 as $key => $value) {
// 	// $s = $value['apb_money'] +$value['apb_fee'];
// 	$sql = 'update ims_cxh_apply_subsidy_car set aplc_totel_retime = aplc_totel_retime-1,aplc_totel_balance = aplc_totel_balance+'.$value['apb_money'].',aplc_re_money = aplc_re_money-'.$value['apb_money'].' where id = '.$value['bus_id'];
// 	// $DB->db->query($sql);
// 	// echo $sql;
// 	// echo '<br>';
// }

// print_r($data1);




//修改 cash_num  异常的数据
// $sql = "SELECT * FROM ims_cxh_cash_log WHERE  cash_num < '-38.02' and cash_bus_type =1 and ctime <1533977183 limit 280";


// $data= $DB->new_query($sql);
// $data = $data->fetchAll(PDO::FETCH_ASSOC); 
// // print_r($data);
// foreach ($data as $key => $value) {
// 	// print_r($value['member_id']);
// 	// echo '<br>';
// 	$s = $value['cash_old']-$value['cash_now'];
// 	// echo $s;

// 	// echo '<br>';
// 	$sql1 = 'update ims_cxh_cash_log set cash_num = -'.$s.' where id = '.$value['id'];
// 	// echo $sql1;
// 	// echo '<br>';
// 	$DB->new_query($sql1);
// }


// //查询手机重复的账号

// $sql = 'SELECT count(*) as num ,id,mobile FROM ims_ewei_shop_member GROUP BY mobile ';

// $data= $DB->new_query($sql);
// $data = $data->fetchAll(PDO::FETCH_ASSOC); 
// $arr =array();
// foreach ($data as $key => $value) {
// 	if($value['num']>1){
// 		$arr[] = $value;
// 	}
// }
// $phone =array();
// foreach ($arr as $key1 => $value1) {
// 	if($value1['id']==1){

// 	}else{
// 		$sql1 = 'SELECT id,mobile,cxhname,realname FROM ims_ewei_shop_member where mobile='.$value1['mobile'];
// 		// echo $sql1;
// 		// echo '<br>';
// 		$date= $DB->new_query($sql1);
// 		$date = $date->fetchAll(PDO::FETCH_ASSOC); 
// 		$phone[] = $date;
// 		// print_r($date);
// 	}
	

	
// }
// // print_r($arr);
// // file_put_contents('mobile.txt',json_encode($phone));
// print_r($phone);



//补贴代理商账户 
// $field = 'su.id,su.apla_totel_retime,su.apla_totel_money,su.apla_totel_days,su.apla_totel_balance,su.apla_re_money,su.apla_re_money_p,su.apla_re_integral,su.apla_re_integral_p,su.apla_re_fee,su.apla_re_fee_p,su.member_id,me.credit2,me.credit1,me.cxhname';
// $sql = 'select '.$field.' from ims_cxh_apply_subsidy_agent as su inner join ims_ewei_shop_member as me on su.member_id=me
// 	.id where su.apla_status=1 and su.is_all_back=1 and su.is_month_back=1 and su.member_id=3565';


// $data= $DB->new_query($sql);
// $data = $data->fetchAll(PDO::FETCH_ASSOC); 
// // print_r($data);
// // exit;
// $nowtime = 1536084601;
// $nowtimes =date('Y-m-d',$nowtime);

// if($data){

// 		foreach ($data as $key => $value) {

// 			if($value['apla_totel_money']>$value['apla_re_money']){
				
// 				//每天返款总金额
// 				$money = round($value['apla_totel_balance']/($value['apla_totel_days']-$value['apla_totel_retime']),2);

// 				//剩余金额(防止返款不足的情况)
// 				if($value['apla_totel_balance']<$money){
// 					$param['apla_totel_balance'] = 0;
// 					$money = $value['apla_totel_balance'];
// 				}else{
// 					$param['apla_totel_balance'] = $value['apla_totel_balance']-$money;
// 				}
// 				$fee_money =0;
// 				if($value['apla_re_fee_p']>0){
// 					$fee_money = round($money*$value['apla_re_fee_p'],2);
// 					$balance_money =  round($money-$fee_money,2);
// 				}else{
// 					$balance_money = $money;
// 				}

				
// 				//已返款天数
// 				$param['apla_totel_retime'] = $value['apla_totel_retime']+1;
// 				//已返金额
// 				$param['apla_re_money']  = $value['apla_re_money']+$money;
// 				//已返积分
// 				// $param['apla_re_integral']  = $value['apla_re_integral']+$point_money;
// 				//平台运维总费
// 				$param['apla_re_fee']  = $value['apla_re_fee']+$fee_money;
// 				$condition['member_id'] = $value['member_id'];
// 				// print_r($param);

// 				//处理申请表
// 				// $res[]=pdo_update('cxh_apply_subsidy_agent',$param,$condition);
// 				$DB->table("ims_cxh_apply_subsidy_agent")->where("id=".$value['id'])->update($param);
// 				// echo $balance_money;
// 				// echo $params;
// 				// echo '<br>';
// 				//添加member表的钱
// 				$params = 'credit2=credit2+'.$balance_money;
// 				$condition1['id'] = $value['member_id'];
// 				$sql = 'update ims_ewei_shop_member set '.$params.' where id='.$value['member_id'];
// 				// $res[]=pdo_update('ewei_shop_member',$params,$condition1);
// 				$DB->new_query($sql);
// 				// echo $sql;
// 				// exit;

// 				//back表记录
// 			    $log['apb_type'] = 2;
// 				$log['bus_id'] = $value['id'];
// 				$log['apb_money'] = $money;
// 				$log['apb_fee'] = $fee_money;
// 				$log['member_id'] = $value['member_id'];
// 				$log['apb_intgral'] = 0;
// 				$log['ctime'] =$nowtime;
// 				$DB->table("ims_cxh_apply_subsidy_back")->insert($log);
// 				// $res[]=pdo_insert('cxh_apply_subsidy_back',$log);


// 				//一总收入
// 				$tol_log['cash_bus_type'] = 2;
// 				$tol_log['cash_type'] = 1;
// 				$tol_log['cash_now'] = $money+$value['credit2'];
// 				$tol_log['cash_old'] = $value['credit2'];
// 				$tol_log['cash_num'] = '+'.$money;
// 				$tol_log['remark'] = '[代理运营补贴] 补贴总金额'.$nowtimes;
// 				$tol_log['member_id'] = $value['member_id'];
// 				$tol_log['ctime'] =$nowtime;
// 				// $res[]=pdo_insert('cxh_cash_log',$tol_log);
// 				$DB->table("ims_cxh_cash_log")->insert($tol_log);

// 				// if($value['apla_re_fee_p']>0){
// 				// 	//平台费
// 				// 	$fee_log['cash_bus_type'] = 2;
// 				// 	$fee_log['cash_type'] = 1;
// 				// 	$fee_log['cash_now'] = $balance_money+$value['credit2'];
// 				// 	$fee_log['cash_old'] = $value['credit2'];
// 				// 	$fee_log['cash_num'] = '-'.$fee_money;
// 				// 	$fee_log['remark'] = '[代理运营补贴] 扣除平台维护费 ' .$nowtimes;
// 				// 	$fee_log['member_id'] = $value['member_id'];
// 				// 	$fee_log['ctime'] =$nowtime;
// 				// 	// $res[]=pdo_insert('cxh_cash_log',$fee_log);
// 				// 	$DB->table("ims_cxh_cash_log")->insert($fee_log);
// 				// }

			
// 			}
// 		}
// 	}
// print_r($data);




//查账

// $sql = "SELECT
// 	FROM_UNIXTIME(ctime,'%Y-%m-%d'),
// member_id,uch_money,ctime,uch_bankUser
// FROM
// 	ims_cxh_user_cash
// WHERE
// 	uch_status = 0
// AND ctime BETWEEN 1535904026
// AND 1535990366";


//  $data= $DB->new_query($sql);
// $data = $data->fetchAll(PDO::FETCH_ASSOC); 
// // print_r($data);



// file_put_contents('cz.txt',serialize($data));







//修正back表



// $sql  = 'SELECT * FROM ims_cxh_apply_subsidy_car WHERE aplc_status =2 and aplc_re_money = 0';



// $data= $DB->new_query($sql);
// $data = $data->fetchAll(PDO::FETCH_ASSOC); 
// foreach ($data as $key => $value) {
// 	$sql = "DELETE FROM ims_cxh_apply_subsidy_back WHERE apb_type=1 and apb_money = 0 and bus_id = ".$value['id'];
// 	$DB->new_query($sql);
// 	echo $sql ;
// 	echo '<br>';
// }
// print_r($data);

// $newarr = array();

// $sql  = 'SELECT * FROM ims_cxh_apply_subsidy_back WHERE apb_money =0 and apb_type =1 GROUP BY bus_id  ';

// $data= $DB->new_query($sql);
// $data = $data->fetchAll(PDO::FETCH_ASSOC); 
// // print_r($data);
// // exit;
// foreach ($data as $key => $value) {
// 	// $sqls = 'select apb_money,bus_id,apb_intgral from ims_cxh_apply_subsidy_back where apb_money!=0 and bus_id='.$value['bus_id'].' limit 1';
// 	// $date= $DB->new_query($sqls);
// 	// $date = $date->fetchAll(PDO::FETCH_ASSOC); 
// 	// // print_r($date);
// 	// // $newarr[] = $date['0'];
// 	// if($date[0]){
// 	// 	if($date[0]['apb_money']>0){
// 		// $sqles = 'update ims_cxh_apply_subsidy_back set apb_money='.$date[0]['apb_money'].',apb_intgral='.$date[0]['apb_intgral'].' where bus_id='.$value['bus_id'].' and apb_money=0 and apb_type=1';
// 		$sqls1 = 'delete from ims_cxh_apply_subsidy_back where apb_type=1 and apb_money=0 and bus_id='.$value['bus_id'];
// 		$DB->new_query($sqls1);
// 		// echo $sqles;
// 		// echo '<br>';
// 	// 	}
// 	// }
	
	
// 	// print_r($date);
// }
// print_r($newarr);














